package cn.broadmax.boot.api;

import cn.broadmax.boot.config.AppBaseProperties;
import cn.broadmax.boot.modules.sys.entity.SysUser;
import cn.broadmax.boot.modules.sys.service.ISysUserService;
import cn.broadmax.boot.base.model.LoginUser;
import jexx.util.BooleanUtil;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 默认ISystemBaseApi的实现类, 可自定义实现
 * @author jeff
 * @date 2020/6/14
 */
public class SystemBaseApiImpl implements ISystemBaseApi {

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private AppBaseProperties appBaseProperties;

    @Override
    public LoginUser getAppUserByUserId(String userId) {
        SysUser sysUser = sysUserService.getById(userId);
        if(sysUser == null){
            return null;
        }

        LoginUser loginUser = new LoginUser();
        loginUser.setUserId(sysUser.getId());
        loginUser.setUsername(sysUser.getUsername());
        loginUser.setRealName(sysUser.getRealName());
        loginUser.setLocked(BooleanUtil.isTrue(sysUser.getLocked()));
        return loginUser;
    }

}
